package http.get;

import annotation.HttpService;
import spark.Request;
import spark.Response;
import static spark.Spark.get;
import static spark.Spark.post;


public abstract class BaseRequest {
    protected HttpService httpService = new HttpService();
    public void init(){
        httpService.bind(this);
        switchResp();
    }

    private void switchResp(){
        if (httpService.getStatus()) {
            get(httpService.getHttpPath() ,(req , resp) ->{
                return callAnyRespone(req ,resp);
            });
        } else {
            post(httpService.getHttpPath(),(req , resp) ->{
                return callAnyRespone(req,resp);
            });
        }
    }


    protected abstract Object callAnyRespone(Request request , Response response);

    protected   String successCommanResp(){
        return "{\"code\":\"200\",\"msg\":\"ok\"}";
    }

    protected  String universalResp(String msg,String code){
        return "{\"code\":\"" + code +"\",\"msg\":\"" + msg + "\"}";


    }
}
